package com.nuonuo.es.utils;

import org.apache.commons.lang3.StringUtils;

import java.util.Calendar;
import java.util.Date;

/**
 * @author duan
 * @version 1.0
 * @date 2023/8/30 18:02
 */
public class DateUtils {
    public static final String DATETIME_NO_SIGN = "yyyyMMddHHmmss";
    public static final String DATETIME = "yyyy-MM-dd HH:mm:ss";

    public DateUtils() {
    }

    public static String getYear(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        int year = calendar.get(1);
        return String.valueOf(year);
    }

    public static Date parseDate(String date, String parsePattern) {
        try {
            return StringUtils.isBlank(date) ? new Date() : org.apache.commons.lang3.time.DateUtils.parseDate(date, new String[]{parsePattern});
        } catch (Exception var3) {
            return new Date();
        }
    }
}
